package com.book.stat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.book.stat.entity.SellStat;
import com.book.stat.mapper.SellStatMapper;
import com.book.stat.service.SellStatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SellServiceImpl extends ServiceImpl<SellStatMapper, SellStat> implements SellStatService {
    @Autowired
    SellStatMapper sellStatMapper;

    @Override
    public List<SellStat> statList(SellStat sellStat) {
        QueryWrapper<SellStat> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(sellStat.getYear())) {
            queryWrapper.eq("year", sellStat.getYear());
        }
        if (StringUtils.isNotEmpty(sellStat.getLocation())) {
            queryWrapper.eq("location", sellStat.getLocation());
        }
        return this.sellStatMapper.selectList(queryWrapper);
    }

    @Override
    public void addSellStat(SellStat sellStat) {
        this.save(sellStat);
    }

    @Override
    public void updateSellStat(SellStat sellStat) {
        this.saveOrUpdate(sellStat);
    }
}
